import axios from 'axios';

const instance = axios.create({
  baseURL: 'http://8.138.12.59:1999', // 后端服务器地址
  timeout: 3000, // 请求超时时间
  headers: { 'Content-Type': 'application/json' }
});

export default {
  fetchUnitsBySemId(id) {
    return instance.get('/unit/showUnits', {
      params: {
        semester_id: id
      }
    });
  },
  //修改unit名字
  UpdateUnitTitle(data) {
    return instance.put('/unit/updateUnitTitle', data)
  },
  //删除unit
  DeleteUnit(id) {
    return instance.delete("/unit/deleteUnitById", {
      params: {
        unit_id: id
      }
    })
  },
  //添加unit（章节和小节
  AddUnit(data) {
    return instance.post("/unit/setUnit", data)
  },
  //修改hmk名字
  UpdateHmkTitle(data) {
    return instance.put('/teacher/homework', data)
  },
  //删除hmk
  DeleteHmk(id) {
    return instance.delete(`/teacher/homework/${id}`)
  },
  //添加hmk
  AddHmk(data) {
    return instance.post("/teacher/homework", data)
  },
  //修改test名字
  UpdateTestTitle(data) {
    return instance.put('/unitTest', data)
  },
  //删除test
  DeleteTest(id) {
    return instance.delete(`/unitTest/deleteUnitTest`, {
      params: {
        unit_test_id: id
      }
    })
  },
  //添加test
  AddTest(data) {
    return instance.post("/unitTest/setUnitTest", data)
  },
  //根据章节id查找sub列表
  FetchSub(unit_id) {
    return instance.get("/unit/showSubsection", {
      params: {
        unit_id: unit_id
      }
    })
  },
  //课程任务
  FetchTask(id) {
    return instance.get('/course/stats', {
      params: {
        semester_id: id
      }
    })
  },
  //选课人数
  FetchCourseCount(id) {
    return instance.get('/course/enrollment-chart', {
      params: {
        semester_id: id
      }
    })
  },
  //视频观看人数
  FetchVideo(id) {
    return instance.get('/course/video-viewers-chart', {
      params: {
        semester_id: id
      }
    })
  },
  //获取单元列表
  FetchUnits(id) {
    return instance.get('/course/getUnits', {
      params: {
        semester_id: id
      }
    })
  },
  //测试成绩
  FetchTest(id) {
    return instance.get(`/course/test-scores`, {
      params: {
        unit_id: id
      }
    });
  },
  //作业成绩
  FetchHmk(id) {
    return instance.get(`/course/homework-scores`, {
      params: {
        unit_id: id
      }
    });
  },
  //获取讨论数据
  FetchDiscussion(id) {
    return instance.get('/course/discussion', {
      params: {
        semester_id: id
      }
    })
  },
  //获得成绩分布
  FetchGrade(id) {
    return instance.get('/course/grades-distribution-chart', {
      params: {
        semester_id: id
      }
    })
  },
  //有效成绩通过率
  FetchPass(id) {
    return instance.get('/course/exam-pass-chart', {
      params: {
        semester_id: id
      }
    })
  },
  //获取分数各种数据
  FetchAverGrade(id) {
    return instance.get('/course/grades', {
      params: {
        semester_id: id
      }
    })
  },
  //设置权重
  FetchPermissions(data) {
    return instance.post('/course/permissions', data,{
    timeout: 10000,
  })
  },
  //获取learningdata
  FetchLearningdata(id) {
    return instance.get('/course/learningData', {
      params: {
        semester_id: id
      },
      timeout: 10000 // 设置超时时间为5000毫秒（5秒）
    })
  },
  //教师注册
  Register(data) {
    return instance.put('/user/register', data)
  },
  //教师登录
  Login(data) {
    return instance.get('/user/login', {
      params: {
        phone_num: data.phone_num,
        password: data.password,
      }
    })
  },
  //获取讨论主题
  GetPost(id) {
    return instance.get('/post/getPost', {
      params: {
        semester_id: id
      }
    })
  },
  //创建主题
  SetPost(data) {
    return instance.post('/post/setPost', data)
  },
  //加载回复评论
  FetchTechReComment(semester_id, publisher_id) {
    return instance.get("/post/TechReply", {
      params: {
        semester_id: semester_id,
        publisher_id: publisher_id
      }
    })
  },
    //删除回复评论
    DeleteReComment(id) {
      return instance.delete("/post/deleteReply", {
        params: {
          comment_id:id
        }
      })
    },
  //获取作业批改作业名称选项列表
  FetchHmkListBySem(semester_id) {
    return instance.get("/teacher/homework/getHmklist", {
      params: {
        semester_id: semester_id
      }
    })
  },
  //根据hmkid获取相应学生作业
  FetchListByhmkid(hmkId) {
    return instance.get("/teacher/homework/getlistByhmkid", {
      params: {
        hmk_id: hmkId
      }
    })
  },
  //批改作业
  UpdateGrade(data) {
    return instance.put("/teacher/homework/grade", data
    )
  },
}

// export default instance;
